package sort;

/**
 * @author Europa
 * @create 2020-05-15 2:30
 */
public class Insertion extends Sort {

    /**
     * 插入排序<br/>
     * 排序可视化 https://www.bilibili.com/video/BV1GW411H7y2
     *
     * @param array int数组
     */
    @Override
    public void sort(int[] array) {
        for (int i = 0; i < array.length; i++) {
            // 逆序获取元素
            for (int j = i; j > 0; j--) {
                if (less(array[j], array[j - 1])) {
                    exchange(array, j, j - 1);
                }
            }
        }

    }
}
